﻿using MengLin.OOP.DesignPattern.SimpleFactory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MengLin.OOP.DesignPattern.Interface;
using MengLin.OOP.DesignPattern.Entity;
using MengLin.OOP.DesignPattern.GeneralService;
using MengLin.OOP.DesignPattern.GeneralService.SqlServer;
using MengLin.OOP.DesignPattern.GeneralService.Orcal;


namespace MengLin.OOP.DesignPattern.SimpleFactory.Client
{
    class Program
    {
        static void Main(string[] args)
        {
            User newUser = new User();
            newUser.Id = 123456;
            newUser.Name = "张三";

            #region 传统写法-上端依赖(直接调用/指定)下端对象，会有依赖
            //{
            //    OrcalUserService orcalUserService = new OrcalUserService();
            //    orcalUserService.CreateUser(newUser);
            //}
            //{
            //    SqlServerUserService sqlServerUserService = new SqlServerUserService();
            //    sqlServerUserService.CreateUser(newUser);
            //}
            #endregion

            #region 传统写法升级
            //{
            //    IUserService orcalUserService = new MengLin.OOP.DesignPattern.Implement.Orcal.OrcalUserService();
            //    orcalUserService.CreateUser(newUser);
            //}
            //{
            //    IUserService sqlServerUserService = new MengLin.OOP.DesignPattern.Implement.SqlServer.SqlServerUserService();
            //    sqlServerUserService.CreateUser(newUser);
            //}
            #endregion

            #region 简单工厂写法，把依赖转移到工厂，把依赖转移到底层
            {
                IUserService iUserService =ObjFactory.CreateInstance(DbType.Orcal);
                iUserService.CreateUser(newUser);
                iUserService.GetUser(1);
            }
            {
                IUserService iUserService = ObjFactory.CreateInstance(DbType.SqlServer);
                iUserService.CreateUser(newUser);
                iUserService.GetUser(1);
            }
            #endregion

            Console.ReadKey();
        }
    }
}
